import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: GaoBo
 * Date: 2021-04-13
 * Time: 18:04
 */

class Person {

}
public class TestDemo {


    public static void main(String[] args) {
        int[] array = {1,2,3,4};// 长度是死的！！     扩容

        int[] array2 = new int[]{1,2,3,4};// 长度是死的！！

        int[] array3 = new int[10];
        array3[0] = 99;
        array3[1] = 199;

        System.out.println(Arrays.toString(array3));
    }

    public static void swap2(int a,int b) {
        int tmp = a;
        a = b;
        b = tmp;
    }

    public static void swap(int[] array) {
        int tmp = array[0];
        array[0] = array[1];
        array[1] = tmp;
    }
    public static void main8(String[] args) {
        int[] array = {10,20};
        System.out.println("交换前："+array[0]+" "+array[1]);
        swap(array);
        System.out.println("交换后："+array[0]+" "+array[1]);
    }

    public static void main7(String[] args) {
        int a = 10;
        int b = 20;
        System.out.println(a);
        System.out.println(b);
        swap2(a,b);
        System.out.println(a);
        System.out.println(b);
    }

    /**
     * 实现一个方法 来打印一个整型数组
     * @param array
     */
    public static void print(int[] array) {
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }
        System.out.println();
    }

    /**
     * 将数组每个元素都扩大2倍！
     * @param array
     */
    public static void change(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = array[i]*2;
        }
    }
    public static void main6(String[] args) {
        int[] array = {1,2,3,4,5};
        print(array);//修改之前
        change(array);
        print(array);//修改之后
    }

    public static void main5(String[] args) {
        int[] array = {1,2,3,4,5};
        print(array);
        System.out.println("==================");
        int[] array2 = {11,21,31,41,51};
        print(array2);
    }

    public static void main4(String[] args) {
       /* int a = 0;
        System.out.println(a);*/
        int[] array = null;
        System.out.println(array.length);//
    }


    public static void main3(String[] args) {
        //局部变量  array  array2  array3
        int[] array = {10,20,30,40};
        //System.out.println(array[1]);
        System.out.println(array[2]);

        /*int[] array2 = new int[5];//定义一个数组

        int[] array3 = new int[]{1,2,3,4,5};

        int a = 10;*/

    }




    public static void main2(String[] args) {
        int[] array = {10,20,30,40};
        //1、遍历数组的方式。  数组名.length 就可以获取到数组的长度
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }
        System.out.println();
        System.out.println("===========for-each=============");
        //2、for-each
        for (int x : array) {
            System.out.print(x+" ");
        }
        System.out.println();
        //3、使用操作数组的工具类来进行数组的打印
        System.out.println("===========xxx=============");
        String ret = Arrays.toString(array);
        System.out.println(ret);
    }
    public static void main1(String[] args) {
       /* int a = 10;
        int a2 = 20;
        int a3 = 30;
        int a4 = 40;*/
        int[] array = {10,20,30,40};

        int[] array2 = new int[5];//定义一个数组

        int[] array3 = new int[]{1,2,3,4,5};

    }
}
